import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:myflutterproject/utils/spUtil.dart';

class FlatButtonDemo extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => FlatButtonState();
}

class FlatButtonState extends State<FlatButtonDemo> {
  int _count = 0;

  void initCount() {
    setState(() {
      _count++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('FlatButton扁平按钮组件'),
        centerTitle: true,
      ),
      body: Column(
        children: <Widget>[
          FlatButton(
            child: Text(
              '登录',
              style: TextStyle(fontSize: 15),
            ),
            //按钮背景色
            // 按钮背景色
            color: Colors.green,
            // 按钮亮度
            colorBrightness: Brightness.dark,
            // 禁用时的背景色
            disabledColor: Colors.grey,
            // 禁用时的文本色
            disabledTextColor: Colors.grey[500],
            // 文本颜色
            textColor: Colors.white,
            // 按钮主题 ButtonTheme ButtonThemeData ButtonTextTheme ThemeData
            textTheme: ButtonTextTheme.normal,
            // 点击效果颜色
            splashColor: Colors.blue,
            // 抗锯齿能力
            clipBehavior: Clip.antiAlias,
            // 内边距
            padding: EdgeInsets.symmetric(vertical: 5.0, horizontal: 20.0),
            // 边框样式
//            shape: Border.all(
//              width: 2.0,
//              color: Colors.deepPurple,
//              style: BorderStyle.solid
//            ),
            // 边框圆角样式
            shape: RoundedRectangleBorder(
                side: BorderSide(
                    width: 2.0,
                    color: Colors.deepPurple,
                    style: BorderStyle.solid),
                borderRadius: BorderRadius.only(
                    topLeft: Radius.circular(10.0),
                    topRight: Radius.circular(10.0),
                    bottomLeft: Radius.circular(10.0),
                    bottomRight: Radius.circular(10.0))),
            onPressed: () => {initCount(), print('点击按钮登录')},
          ),
          Text('$_count'),
          //带图标的按钮
          TextButton.icon(
            onPressed: () => Navigator.pop(context),
            icon: Icon(
              Icons.android,
              size: 28.0,
            ),
            label: Text(
              '点击返回上一级',
              style: TextStyle(fontSize: 26.0),
            ),
            style: TextButton.styleFrom(
              primary: Colors.grey[850],
              backgroundColor: Colors.yellow,
              padding: EdgeInsets.symmetric(vertical: 15, horizontal: 10),
              shape: StadiumBorder(
                  side: BorderSide(
                      color: Colors.yellow, style: BorderStyle.solid)),
            ),
          ),
          //清除缓存
          OutlinedButton(
              onPressed: () async {
                await SpUtil.clear();
                print('边框按钮点击');
              },
              child: Text(
                '清除share缓存',
                style: TextStyle(fontSize: 16.0),
              ),
            style: OutlinedButton.styleFrom(
              primary: Colors.grey[850], //字体颜色
              padding: EdgeInsets.symmetric(horizontal: 20.0, vertical: 10.0),
              side: BorderSide(
                  width: 2.0, color: Colors.yellow, style: BorderStyle.solid),
              shape: StadiumBorder(),
            ),
          ),
        ],
      ),
    );
  }
}
